﻿using System;
using System.Web.Security;
using System.Web.UI;
using QuickORM.BLL;
using QuickORM.Common;
using QuickORM.Entity;

public partial class _Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void loginBtn_Click(object sender, EventArgs e)
    {
        var userName = Util.querySQL(idInput.Value.Trim());

        if (string.IsNullOrEmpty(userName))
        {
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "alert('用户名不能为空!');", true);
            return;
        }
        var userPwd = pwdInput.Value;
        if (string.IsNullOrEmpty(userPwd))
        {
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "alert('密码不能为空!');", true);
            return;
        }
        var loginuser = new T_UserInfo();
        loginuser.UserName = userName;
        loginuser.UserPWD = Util.SHA1(userPwd);
        var currUser = new T_UserInfo();
        if (BLLFactory<T_UserInfoManager>.Instance.Login(loginuser, out currUser))
        {
            Session.Add("UserID", currUser.UserID.ToString());
            Session.Add("UserName", currUser.UserName);
            Session.Add("RealName", currUser.RealName);
            Session.Add("Email", currUser.Email);
            Session.Add("Tel", currUser.Tel);
            Session.Add("RoleID", currUser.RoleID.ToString());
            FormsAuthentication.SetAuthCookie(currUser.UserID.ToString(), false);
            FormsAuthentication.RedirectFromLoginPage(currUser.UserID.ToString(), false);
            Response.Redirect("Manage/Main.aspx");
        }
        else
        {
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "alert('用户名密码不正确!');", true);
        }
    }
}